﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Framework.Domain;
using Framework.Sample.Domain.Event;
using Framework.Event;

namespace Framework.Sample.Domain.Model
{
    public class Account : AggregateRoot
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public int Age { get; set; }
        public string Password { get; set; }
        public void Register(string name, int age)
        {
            OnEvent(new AccountRegistered
            {
                AccountID = 0,
                Name = name,
                Age = age
            });
        }

        [EventHandler]
        protected void HandleAccountRegistered(AccountRegistered e)
        {
            ID = e.AccountID;
            Name = e.Name;
            Age = e.Age;
        }

        public void ChangePassword(string pwd)
        {
            OnEvent(new PasswordChanged
            {
                AccountID = 0,
                OldPassword = this.Password,
                NewPassword = pwd
            });
        }

        [EventHandler]
        protected void HandlePasswordChanged(PasswordChanged e)
        {
            Password = e.NewPassword;
        }
    }
}
